package org.xxpay.pay.channel.xxpay;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @description: xxpay
 */
@Component
public class XxpayConfig {

    public static final String CHANNEL_NAME = "xxpay"; //渠道名称
    public static final String CHANNEL_NAME_PAY = CHANNEL_NAME + "_pay";        // 统一支付

    private String mchId; // 商户ID

    private String key;  // 商户Key

    private String appId; //应用ID

    private String productId; // 产品ID

    private String reqUrlHost;  // 请求地址域名

    // 模式 form | sdk | url 默认form方式
    private String mode = "form";

    // 取支付地址字段,1 表示取payJumpUrl  2表示取payUrl  默认1
    private String urlField = "1";

    public XxpayConfig(){}

    public XxpayConfig(String payParam) {
        Assert.notNull(payParam, "init xxpay config error");
        JSONObject object = JSONObject.parseObject(payParam);
        this.mchId = object.getString("mchId");
        this.key = object.getString("key");
        this.appId = object.getString("appId");
        this.productId = object.getString("productId");
        this.reqUrlHost = object.getString("reqUrlHost");
        this.mode = StringUtils.isNotBlank(object.getString("mode")) ? object.getString("mode") : this.mode;
        this.urlField = StringUtils.isNotBlank(object.getString("urlField")) ? object.getString("urlField") : this.urlField;
    }

    public String getMchId() {
        return mchId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getReqUrlHost() {
        return reqUrlHost;
    }

    public void setReqUrlHost(String reqUrlHost) {
        this.reqUrlHost = reqUrlHost;
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public String getUrlField() {
        return urlField;
    }

    public void setUrlField(String urlField) {
        this.urlField = urlField;
    }
}
